src: add fallthrough attribute
authorÁlvaro Fernández Rojas <[email protected]>
Fri, 14 Nov 2025 07:19:17 +0000 (08:19 +0100)
committerÁlvaro Fernández Rojas <[email protected]>
Mon, 17 Nov 2025 07:28:54 +0000 (08:28 +0100)
- Enable fallthrough warnings.
- Use fallthrough attribute instead of comments.

Signed-off-by: Álvaro Fernández Rojas <[email protected]>
Link: https://github.com/openwrt/odhcp6c/pull/120
CMakeLists.txt
src/dhcpv6.c
src/odhcp6c.h

index 90678190a628674f28e514f65d5e297788238cff..ebbe69b9054e24f6c3f99aa1c114fdb9f4b44196 100644 (file)
@@ -26,6 +26,7 @@ target_compile_options(${PROJECT_NAME} PRIVATE -Werror=implicit-function-declara
 target_compile_options(${PROJECT_NAME} PRIVATE -Wformat)
 target_compile_options(${PROJECT_NAME} PRIVATE -Werror=format-security)
 target_compile_options(${PROJECT_NAME} PRIVATE -Werror=format-nonliteral)
+target_compile_options(${PROJECT_NAME} PRIVATE -Wimplicit-fallthrough=5)
 target_compile_options(${PROJECT_NAME} PRIVATE -Wno-unused-parameter)
 target_compile_options(${PROJECT_NAME} PRIVATE -Wmissing-declarations)
 
index 7bcaee06e56dda80c4cedbf421d12740b41dcb48..7f73699141dab9f86fe41d79e0bfe3f9715ea6c6 100644 (file)
@@ -1144,11 +1144,11 @@ static int dhcpv6_handle_reconfigure(enum dhcpv6_msg orig, const int rc,
                        case DHCPV6_MSG_REBIND:
                                if (t2 != UINT32_MAX)
                                        t2 = 0;
-                       // Fall through
+                               _o_fallthrough;
                        case DHCPV6_MSG_RENEW:
                                if (t1 != UINT32_MAX)
                                        t1 = 0;
-                       // Fall through
+                               _o_fallthrough;
                        case DHCPV6_MSG_INFO_REQ:
                                msg = odata[0];
                                syslog(LOG_NOTICE, "Need to respond with %s in reply to %s",
@@ -2146,7 +2146,7 @@ int dhcpv6_send_request(enum dhcpv6_msg type)
        default:
                syslog(LOG_NOTICE, "Send %s message (elapsed %"PRIu64"ms, rc %d)",
                                retx->name, elapsed, retx->rc);
-       // Fall through
+               _o_fallthrough;
        case DHCPV6_MSG_SOLICIT:
        case DHCPV6_MSG_INFO_REQ:
                dhcpv6_send(type, retx->tr_id, elapsed / 10);
index 02578ccb0b95bb036c39d4a93728d4dc2fa59352..42c645d1ed363fd4fdab415be0c896012aaa6bd7 100644 (file)
 #define _o_aligned(n) __attribute__((aligned(n)))
 #endif /* _o_aligned */
 
+#ifndef _o_fallthrough
+#define _o_fallthrough __attribute__((__fallthrough__))
+#endif /* _o_fallthrough */
+
 #ifndef _o_packed
 #define _o_packed __attribute__((packed))
 #endif /* _o_packed */